import ray
from ray import tune
import pandas as pd

# from sklearn.datasets import load_breast_cancer
#
# dataset = load_breast_cancer()

# ray.init(num_cpus=2)

# Load data.
dataset = ray.data.read_csv("breast_cancer.csv")
print(dataset)
dataset.show(limit=1)


# Find rows with spepal length < 5.5 and petal length > 3.5.
def transform_batch(df: pd.DataFrame) -> pd.DataFrame:
    return df[(df["x_1"] < 17) & (df["x_2"] > 11)]


transformed_dataset = dataset.map_batches(transform_batch)
print(transformed_dataset)
transformed_dataset.show(limit=1)

batches = transformed_dataset.iter_batches(batch_size=8)
# for i in batches:
#     print(i)

transformed_dataset.write_parquet("breast_cancer")

dataset2 = ray.data.read_parquet('breast_cancer')







# 1. Define an objective function.
def objective(config):
    score = config["a"] ** 2 + config["b"]

    return {"score": score}


# 2. Define a search space.
search_space = {
    "a": tune.grid_search([0.001, 0.01, 0.1, 1.0]),
    "b": tune.grid_search([1, 2, 3]),
}

# 3. Start a Tune run and print the best result.
tuner = tune.Tuner(objective, param_space=search_space)
results = tuner.fit()
print(results.get_best_result(metric="score", mode="max").config)
